export default {
	// 为当前模块开启命名空间
	namespaced: true,

	state: () => ({
		// 收货地址
		addressInfo: JSON.parse(uni.getStorageSync('address') || '{}'),
	}),

	// 方法
	mutations: {
		// 更新收货地址
		updateAddress(state, address) {
			state.addressInfo = address
			this.commit('address/saveAddressStorage')
		},
		
		
		saveAddressStorage(state) {
		      uni.setStorageSync('address', JSON.stringify(state.addressInfo))
		},
		
		
		updateAllGoodsState(state, newState) {
		  // 循环更新购物车中每件商品的勾选状态
		  state.cartList.forEach(item => item.goods_state = newState)
		  // 持久化存储到本地
		  this.commit('m_cart/saveToStorage')
		}
	},

	// 数据包装器
	getters: {
		addstr(state) {
		    if (!state.addressInfo.provinceName) return ''
		
		    // 拼接 省，市，区，详细地址 的字符串并返回给用户
		    return state.addressInfo.provinceName + state.addressInfo.cityName + state.addressInfo.countyName + state.addressInfo.detailInfo
		  }
		
		
	},
}
